package com.itheima.store.service.impl;

import java.sql.SQLException;
import java.util.List;


import com.itheima.store.dao.DeptmanagerDao;
import com.itheima.store.dao.PostManagerDao;

import com.itheima.store.domain.Dept;
import com.itheima.store.domain.Post;

import com.itheima.store.service.DeptManagerService;
import com.itheima.store.service.PostManagerService;
import com.itheima.store.utils.BeanFactory;

import net.sf.ehcache.Cache;
import net.sf.ehcache.CacheManager;
import net.sf.ehcache.Element;
/**
 * 分类的Service的实现类
 * @author admin
 *
 */
public class PostManagerServiceImpl implements PostManagerService {

	//@Override
	public List<Post> findAllPost()throws SQLException {
		List<Post> list = null;
		PostManagerDao postManagerDao =(PostManagerDao)BeanFactory.getBean("postManagerDao");
		list = postManagerDao.findAllPost();
		return list;
	}

	@Override
	public void savePost(Post post) throws SQLException {
		// TODO Auto-generated method stub
		PostManagerDao postManagerDao =(PostManagerDao)BeanFactory.getBean("postManagerDao");
		postManagerDao.savePost(post);
		//清空缓存
		//CacheManager cacheManager = CacheManager.create(DeptManagerServiceImpl.class.getClassLoader().getResourceAsStream("ehcache.xml"));
		// 从配置文件中获取名称为categoryCache缓存区
		//Cache cache = cacheManager.getCache("deptmanagerCache");
		//cache.remove("list");
		
	}

	@Override
	public Post queryPost(String post_id) throws SQLException {
		PostManagerDao postManagerDao =(PostManagerDao)BeanFactory.getBean("postManagerDao");
		
		return postManagerDao.queryPost(post_id);
	}

	@Override
	public void updatePost(Post post) throws SQLException {
		PostManagerDao postManagerDao =(PostManagerDao)BeanFactory.getBean("postManagerDao");
		postManagerDao.updatePost(post);
	}

	@Override
	public void deletePost(String post_id) throws SQLException {
		// TODO Auto-generated method stub
		PostManagerDao postManagerDao =(PostManagerDao)BeanFactory.getBean("postManagerDao");
		postManagerDao.deletePost(post_id);
		
	}

}
